/**
 *@note Copyright 2012-2022 CETHIK All Rights Reserved.
 *@brief 静态地图层文件
 *@author tuyinan
 *@data 2022-04-xx
 */
#ifndef COSTMAP_2D_STATIC_LAYER_H_
#define COSTMAP_2D_STATIC_LAYER_H_

#include <costmap_2d/costmap_layer.h>
#include <costmap_2d/data_collector.h>
#include <costmap_2d/footprint.h>
#include <costmap_2d/layered_costmap.h>

#include <thread>

namespace costmap_2d {
/**
 *@brief 静态地图层
 *@author tuyinan
 *@version 2022-04-xx
 */
class StaticLayer : public CostmapLayer {
 public:
  /**
   *@brief 构造函数
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  StaticLayer();
  /**
   *@brief 析构函数
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual ~StaticLayer();
  /**
   *@brief 初始化函数
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void onInitialize();
  /**
   *@brief 激活层
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void activate();
  /**
   *@brief 取消激活
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void deactivate();
  /**
   *@brief 重置
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void reset();
  /**
   *@brief 获取静态地图的线程
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void getDatafromCollector();
  /**
   *@brief 更新地图边际
   *@param double robot_x 机器人位姿x
   *@param double robot_y 机器人位姿y
   *@param double robot_yaw 机器人角度
   *@param double* min_x 最小x
   *@param double* min_y 最小y
   *@param double* max_x 最大x
   *@param double* max_y 最大y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void updateBounds(double robot_x, double robot_y, double robot_yaw,
                            double* min_x, double* min_y, double* max_x,
                            double* max_y);
  /**
   *@brief 更新占位
   *@param double robot_x 机器人位姿x
   *@param double robot_y 机器人位姿y
   *@param double robot_yaw 机器人角度
   *@param double* min_x 最小x
   *@param double* min_y 最小y
   *@param double* max_x 最大x
   *@param double* max_y 最大y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void updateFootprint(double robot_x, double robot_y, double robot_yaw,
                               double* min_x, double* min_y, double* max_x,
                               double* max_y);
  /**
   *@brief 更新代价
   *@param costmap_2d::Costmap2D& 代价地图类
   *@param int min_i 最小的x
   *@param int min_j 最小的y
   *@param int max_i 最大的x
   *@param int max_j 最大的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void updateCosts(costmap_2d::Costmap2D& master_grid, int min_i,
                           int min_j, int max_i, int max_j);
  /**
   *@brief 适配主地图大小
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void matchSize();

 private:
  /**
   *@brief 外部值转换为内部用的代价值
   *@param unsigned char value 值
   *@return unsigned char 内部值
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  unsigned char interpretValue(unsigned char value);
  /// 是否收到地图
  bool map_received_;
  /// 是否更新了数据
  bool has_updated_data_;
  /// 机器人坐标核地图大小
  unsigned int x_, y_, width_, height_;
  /// 是否追踪未知区域
  bool track_unknown_space_;
  /// 是否使用最大福大方法
  bool use_maximum_;
  /// 是否采用三元表示地图
  bool trinary_costmap_;
  /// 是否清除机器人占位
  bool footprint_clearing_enabled_;
  /// 是否为障碍物阈值，未知区域代价
  unsigned char lethal_threshold_, unknown_cost_value_;
  /// 是否获取数据
  bool collect_signal_;
  /// 机器人转换后的占位
  std::vector<costmap_2d::Point> transformed_footprint_;
};

}  // namespace costmap_2d

#endif  // COSTMAP_2D_STATIC_LAYER_H_
